//package com.tiancheng.trade.settlement.util;
//
//import com.fasterxml.jackson.core.type.TypeReference;
//import com.fasterxml.jackson.databind.ObjectMapper;
//import com.sensorsdata.analytics.javasdk.SensorsAnalytics;
//import com.tiancheng.trade.settlement.enums.OrderSourceEnum;
//import com.tiancheng.trade.settlement.model.order.SubOrder;
//import com.tiancheng.trade.settlement.service.order.ISubOrderService;
//import com.tiancheng.trade.settlement.util.queue.AbstractCustomQueueConsumer;
//import com.tiancheng.trade.settlement.util.queue.RedisDelayQueueEnum;
//import com.tiancheng.trade.settlement.util.queue.RedisDelayQueueUtil;
//import lombok.extern.slf4j.Slf4j;
//import org.apache.commons.collections.MapUtils;
//import org.apache.commons.lang3.StringUtils;
//import org.springframework.stereotype.Component;
//
//import javax.annotation.Resource;
//import java.math.BigDecimal;
//import java.util.ArrayList;
//import java.util.List;
//import java.util.Map;
//import java.util.concurrent.TimeUnit;
//
///**
// * @Author: likailun
// * @Description:
// * @Date: create in 2022/12/23 16:08
// */
//@Component
//@Slf4j
//public class SensorChannelHandle extends AbstractCustomQueueConsumer {
//    @Resource
//    private SensorsAnalytics sensorsAnalytics;
//    @Resource
//    private ObjectMapper objectMapper;
//    @Resource
//    private JacksonJsonUtil jacksonJsonUtil;
//    @Resource
//    private RedisDelayQueueUtil redisDelayQueueUtil;
//    @Resource
//    private ISubOrderService subOrderService;
//
//    private static List<String> sources = new ArrayList<String>() {{
//        add("魔方");
//        add("线路");
//        add("订单");
//    }};
//
//    /**
//     * 渠道参数传递上报
//     */
//    public static final String EVENT_NAME = "Channel_Param_Transmit";
//
//    @Override
//    public String getQueueName() {
//        return RedisDelayQueueEnum.CHANNEL_REPORT_PUSH_DELAY_QUEUE.getCode();
//    }
//
//    @Override
//    public Integer getPullIntervalSeconds() {
//        return 2;
//    }
//
//    @Override
//    public void execute(Object o) {
//        try {
//            this.channelDataHandle((Map<String, String>) o);
//        } catch (Exception e) {
//            log.error("渠道广告消息推送神策异常,", e);
//        }
//    }
//
//    private void channelDataHandle(Map<String, String> params) throws Exception {
//        Map<String, Object> data = objectMapper.readValue(jacksonJsonUtil.toJson(params.get("data")), new TypeReference<Map>() {
//        });
//        String uid = MapUtils.getString(data, "uid");
//        data.remove("uid");
//        final String orderId = MapUtils.getString(data, "order_id");
//        // 什么是sb需求
//        if (StringUtils.isNotEmpty(orderId)) {
//            final List<SubOrder> subOrders = subOrderService.findByOrderId(orderId);
//            int payAmount = subOrders.stream().mapToInt(SubOrder::getPayAmount).sum();
//            data.put("products_name", subOrders.get(0).getProductName());
//            data.put("products_id", subOrders.get(0).getProductId());
//            data.put("pay_amount", new BigDecimal(payAmount).divide(new BigDecimal(100),2,BigDecimal.ROUND_UP));
//            //产品类型,线路/套餐/...
//            data.put("products_category", OrderSourceEnum.getDesc(subOrders.get(0).getOrderSource()));
//            sensorsAnalytics.track(uid, true, EVENT_NAME, data);
//            log.info("推送广告数据到神策成功：{}", jacksonJsonUtil.toJson(data));
//        }
//    }
//
//    public void pushMessage(Map<String, String> dataMap) {
//        redisDelayQueueUtil.addDelayQueue(dataMap, 5, TimeUnit.MINUTES, this.getQueueName());
//        log.info("消息存入延迟消息队列成功");
//    }
//
//}
